package com.ophiux.system.controller;

import com.ophiux.common.core.utils.R;
import com.ophiux.common.security.annotation.Inner;
import com.ophiux.system.model.entity.SysTenant;
import com.ophiux.system.service.SysMenuService;
import com.ophiux.system.service.SysTenantService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequiredArgsConstructor
@RequestMapping("/tenant")
@Api(tags = "租户管理")
public class SysTenantController {

	private final SysTenantService sysTenantService;

	private final SysMenuService sysMenuService;


	/**
	 * 查询全部有效的租户
	 * @return
	 */
	@Inner(value = false)
	@GetMapping("/list")
	public R list() {
		//过滤：1.状态正常 2.开始时间小于等于当前时间 3.结束时间大于等于当前时间
		List<SysTenant> tenants = sysTenantService.getNormalTenant().stream()
				.filter(tenant -> tenant.getStartTime().isBefore(LocalDateTime.now()))
				.filter(tenant -> tenant.getEndTime().isAfter(LocalDateTime.now())).collect(Collectors.toList());
		return R.ok(tenants);
	}
}
